﻿//公共共同脚本
var ApiUrl = "http://localhost:6260/";
var LoginUserID = "1";
var LoginUserName = "张三";
$(function () {
    //前台判断是否有令牌，否则直接跳转登录页面
    var storage = window.localStorage;
    var ticket = storage.getItem('token');
    if (ticket == null || ticket == "" || ticket == undefined) {
        location.href = "login.html";
        $("#per_logout").html('<a href="login.html">登录</a>');
    } else {
        $("#per_logout").html('<a href="javascript;" onclick="logout()">退出</a>');
        var storage = window.localStorage;
        var userid = storage.getItem('userid');
        var account = storage.getItem('account');
        var name = storage.getItem('name');
        var pwd = storage.getItem('pwd');
        if (userid == null || userid == "" || userid == undefined ||
           account == null || account == "" || account == undefined ||
           name == null || name == "" || name == undefined ||
           pwd == null || pwd == "" || pwd == undefined) {
            location.href = "login.html";
        } else {
            LoginUserID = userid;
            LoginUserName = name;
        }
    }

})
function logout() {
    //删除Token
    var storage = window.localStorage;
    storage.removeItem("token");//清除token
    storage.removeItem("userid");
    storage.removeItem("account");//清除记住账号
    storage.removeItem("name");
    storage.removeItem("pwd");//清除记住密码
    storage.removeItem("online");//清除记住密码状态
    location.href = "login.html";
}